package com.jcy.jcyrxjava.flutter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.jcy.jcyrxjava.R;
import com.jcy.jcyrxjava.activity.AnimActivity;
import com.jcy.jcyrxjava.timeselect.SelectTimeActivity;

import io.flutter.embedding.android.FlutterFragment;


public class FlutterTestActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flutter_test);
        findViewById(R.id.button_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(FlutterTestActivity.this, AnimActivity.class));
            }
        });
        findViewById(R.id.button_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(FlutterTestActivity.this, SelectTimeActivity.class));
            }
        });
        inJionFlutter();
    }
    private void inJionFlutter() {
//        FlutterEngine flutterEngine = new FlutterEngine(this);
//        flutterEngine.getDartExecutor().executeDartEntrypoint(
//                DartExecutor.DartEntrypoint.createDefault()
//        );
//        FlutterView flutterView = new FlutterView(this);
//        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
//                ViewGroup.LayoutParams.MATCH_PARENT,
//                ViewGroup.LayoutParams.MATCH_PARENT);
//        FrameLayout flContainer = findViewById(R.id.fl_container);
//        flContainer.addView(flutterView, lp);
//        // 关键代码，将Flutter页面显示到FlutterView中
//        flutterEngine.getNavigationChannel().setInitialRoute("route1");
//        flutterView.attachToFlutterEngine(flutterEngine);

        // 通过FlutterFragment引入Flutter编写的页面
        FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
                .initialRoute("/welcomePage11")
                .build();
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.fl_container, flutterFragment)
                .commit();
    }
}
